#!/usr/bin/perl

# 1 indicates the last letter of the segment, otherwise 0

use strict;

open(my $fh, '<', "ZuluWordList.txt") or die $!;
open(my $output, '>', "ZuluSegment2.txt") or die $!;

while(!eof($fh))
{
    my $line = <$fh>;
    if($line =~ /,/)
    {
        next;
    }
    
    $line =~ s/(^\w+)\s+//;
    my $word = $1;

    my @seg = split(//, $line);

    my @syl = ();

    my $count = 1;
    for(my $j = 0; $j < $#seg; $j++)
    {
        if($seg[$j] eq ' ')
        {
            $count = 1;
            next;
        }

        push(@syl,$count);
        push(@syl,' ');
        $count++;
    }

    my $segment = join('',@syl);

    print $output "$word $segment\n";
}

close($fh);
close($output);
